package logic

import (
	"context"
	"fmt"
	"sz2/C/rpc/model/mysql"

	"sz2/C/rpc/good"
	"sz2/C/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsShowLogic {
	return &GoodsShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsShowLogic) GoodsShow(in *good.GoodsShowRequest) (*good.ListItem, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}
	err := g.Show(int(in.Id))
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}

	return &good.ListItem{
		UserId:     int64(g.UserId),
		GoodsTitle: g.GoodsTitle,
		GoodsPrice: float32(g.GoodsPrice),
		GoodsCover: g.GoodsCover,
		GoodsStock: int64(g.GoodsStock),
		LikeCount:  int64(g.LikeCount),
		GoodId:     int64(g.ID),
	}, nil
}
